package cn.dg.manager.common.entity;

import java.io.Serializable;
import java.util.List;

/**
 * 
 * 分页对象
 * 
 * @author duzh
 * @version [版本号, 2018年8月21日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class PageEntity<T> implements Serializable
{
    /**
     * 注释内容
     */
    private static final long serialVersionUID = 1267254780642590743L;

    /**
     * 当前页码 默认第一页
     */
    private int pageNo = 1;
    
    /**
     * 每页显示的记录数，默认是20
     */
    private int pageSize = 20;
    
    /**
     * 总记录数
     */
    private int totalRecord;
    
    /**
     * 总页数
     */
    private int totalPage;
    
    /**
     * 对应的当前页记录
     */
    private List<T> results;
    
    /**
     * 查询条件
     */
    private Object params;
    
    public int getPageNo()
    {
        return pageNo;
    }
    
    public void setPageNo(int pageNo)
    {
        this.pageNo = pageNo;
    }
    
    public int getPageSize()
    {
        return pageSize;
    }
    
    public void setPageSize(int pageSize)
    {
        this.pageSize = pageSize;
    }
    
    public int getTotalRecord()
    {
        return totalRecord;
    }
    
    public void setTotalRecord(int totalRecord)
    {
        this.totalRecord = totalRecord;
        
        // 在设置总页数的时候计算出对应的总页数，在下面的三目运算中加法拥有更高的优先级，所以最后可以不加括号。
        int totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
        this.setTotalPage(totalPage);
    }
    
    public int getTotalPage()
    {
        return totalPage;
    }
    
    public void setTotalPage(int totalPage)
    {
        this.totalPage = totalPage;
    }
    
    public List<T> getResults()
    {
        return results;
    }
    
    public void setResults(List<T> results)
    {
        this.results = results;
    }
    
    public Object getParams()
    {
        return params;
    }
    
    public void setParams(Object params)
    {
        this.params = params;
    }
    
    @Override
    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        builder.append("{pageNo=");
        builder.append(pageNo);
        builder.append(", pageSize=");
        builder.append(pageSize);
        builder.append(", totalRecord=");
        builder.append(totalRecord);
        builder.append(", totalPage=");
        builder.append(totalPage);
        builder.append(", results=");
        builder.append(results);
        builder.append(", params=");
        builder.append(params);
        builder.append("}");
        return builder.toString();
    }
}